{extend name="main" /}

{block name="body"}
{include file="breadcrumb" /}
<div class="layui-fluid">
	<div class="layui-card">
		<div class=" layui-card-header layuiadmin-card-header-auto">
			<form class="layui-form" method="get">
				<input type="hidden" name="bcid" value="{:input('bcid')}"><!--保留当前位置的bcid参数-->
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">名称</label>
						<div class="layui-input-inline">
							<input type="text" name="name" placeholder="请输入关键字" value="{:input('name')}"
								autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">商品分类</label>
						<div class="layui-input-inline">
							<select name="typeid" lay-filter="typeid">
								<option value="">--不限--</option>
								{foreach name="type" item="v" key="k"}
								<option value="{$v.id}">{$v.name}</option>
								{/foreach}
							</select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">商品类别</label>
						<div class="layui-input-inline">
							<select name="category_id">
								<option value="">--不限--</option>
								{foreach name="category" item="v" key="k"}
								<option value="{$v.id}">{$v.title}</option>
								{/foreach}

							</select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">商品学科</label>
						<div class="layui-input-inline">
							<select name="subject_id">
								<option value="">--不限--</option>
								{foreach name="subject" item="v" key="k"}
								<option value="{$v.id}">{$v.title}</option>
								{/foreach}

							</select>
						</div>
					</div>
					<!-- <div class="layui-inline">
                        <label class="layui-form-label">库存</label>
                        <div class="layui-input-inline">
                            <input type="text" name="number" placeholder="请输入关键字" value="{:input('number')}" autocomplete="off" class="layui-input" >
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">价格</label>
                        <div class="layui-input-inline">
                            <input type="text" name="price" placeholder="请输入关键字" value="{:input('price')}" autocomplete="off" class="layui-input" >
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline">
                            <select name="status">
                                <option value="">--不限--</option>
                                <option value="1" {if condition="input('status')!='' and (input('status') eq '1')" } selected="selected" {/if}>启用</option>
                                <option value="2" {if condition="input('status')!='' and (input('status') eq '2')" } selected="selected" {/if}>禁用</option>
                            </select>
                        </div>
                    </div> -->
					<!-- <div class="layui-inline">
                        <label class="layui-form-label">开始日期</label>
                        <div class="layui-input-inline">
                            <input type="text" name="start_date" id="start_date" value="{:input('start_date')}"
                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">截止日期</label>
                        <div class="layui-input-inline">
                            <input type="text" name="end_date" id="end_date" value="{:input('end_date')}"
                                   placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                    </div> -->
					<div class="layui-inline">
						<button class="layui-btn">
							<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
						</button>
					</div>
				</div>
			</form>
		</div>
		<div class="layui-card-body">
			<div class="btn-box">
		<!-- 		<a href="{:url('add')}" class="layui-btn layui-btn-sm xn_open" data-width="90%"
					data-height="94%">添加商品管理</a> -->
				<button type="button" lay-on="deleteAll" class="layui-btn layui-btn-danger layui-btn-sm" title="">
					删除选中
				</button>
			</div>
			<table class="layui-table">
				<thead>
					<tr>
						<th width="25">
							<div class="layui-form">
								<input type="checkbox" name="selectAll" lay-filter="selectAll">
							</div>
						</th>
						<!-- <th width="25">ID</th> -->
						<th>名称</th>
						<th>首页</th>
						<th>分类</th>
						<th>类别</th>
						<th>学科</th>
						<th>库存</th>
						<th>价格</th>

						<!-- <th>时间</th> -->
						<th width="120">操作</th>
					</tr>
				</thead>
				<tbody>
					{foreach name="product" item="vo"}
					<tr>
						<td>
							<div class="layui-form">
								<input class="item-id" type="checkbox" name="id[]" value="{$vo.id}">
							</div>
						</td>
						<!-- <td>{$vo.id}</td> -->
						<td>{$vo.name}</td>
						<td> {$vo.home}</td>
						<td>{$vo.type}</td>
						<td>{$vo.category}</td>
						<td>{$vo.subject}</td>
						<td>{$vo.number}</td>
						<td>{$vo.price}</td>

						<!-- <td>{$vo.create_time}</td> -->
						<td>
							<a href="{:url('select',array('product_id'=>$vo['id']))}" class="layui-btn layui-btn-sm xn_open"
								data-width="90%" data-height="94%">
								上架
							</a>
							<!-- <a href="{:url('delete',array('id'=>$vo['id']))}"
                           class="layui-btn layui-btn-danger layui-btn-sm xn_delete">
                            删除
                        </a> -->
						</td>
					</tr>
					{/foreach}
				</tbody>
			</table>
			<div class="layui-row">
				<div class="pages">{$list|raw}</div>
				{include file="list_rows" /}
			</div>
		</div>
	</div>

</div>
{/block}

{block name="js"}
<script>
	layui.use('laydate', function() {
		var laydate = layui.laydate;

		laydate.render({
			elem: '#start_date'
		});
		laydate.render({
			elem: '#end_date'
		});
	});

	//全选
	layui.use(function() {
		var form = layui.form;
		var layer = layui.layer;
		var util = layui.util;

		//全选
		form.on('checkbox(selectAll)', function(data) {
			var child = $(".item-id");
			child.each(function(index, item) {
				item.checked = data.elem.checked;
			});
			form.render('checkbox');
		});

		//选中删除
		util.on('lay-on', {
			deleteAll: function() {
				var child = $(".item-id");
				var ids = [];
				child.each(function(index, item) {
					if (item.checked === true) {
						ids.push(item.value)
					}
				});
				if (ids.length === 0) {
					layer.msg('未选中数据', {
						icon: 2
					});
					return false;
				}
				layer.confirm('确定要删除所选吗？', {
					btn: ['确定', '关闭'] //按钮
				}, function() {
					var url = "{:url('delete')}";
					$.post(url, {
						id: ids
					}, function(res) {
						if (res.code === 1) {
							layer.msg('删除成功', {
								icon: 1,
								time: 1000
							}, function() {
								window.location.reload();
							});
						} else {
							layer.msg(res.msg, {
								icon: 2
							});
						}
					}, 'json')
				});
			}
		});
	});
</script>
{/block}